Repository navigation
Type a method call by its receiver's class so Python and JavaScript truncate b.size() / 2 [patch] - #281
Merged
Conversation
…runcate b.size() / 2 [patch] #273 typed only receiver-less calls, so a call on a receiver still fell through to unknown type and the Python and JavaScript division and remainder overrides kept true division and flooring: `b.doubled(a) / 4` gave -3.5 for a = -7 where the C family gives -3, even with `doubled` declared `int` on `Box` and `b` typed `Box`. A call with a receiver now takes the receiver's static type, finds the one ClassDeclaration in the tree with that name, and uses the return type of the one method among its own members with the callee's name. An untyped receiver, a class declared nowhere or more than once, an inherited method and an overload all stay unknown, which keeps today's behaviour. An ExpectedType still wins. Fixes #280 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tgs9bqa4b49KCmByF6PHfP
|
This was referenced Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #280
What was wrong
#273 (PR #276) gave
StandardLanguageGenerator.StaticTypea case for receiver-less calls only. A call with a receiver still came out as unknown type, soIsIntegerArithmeticreturned false and the Python and JavaScript/and%overrides kept true division. Fora = -7,b.doubled(a) / 4gave -3.5, while C# and the C family give -3. That happened even withBox.doubleddeclaredintandbtypedBox.Change
CallExpression { Receiver: not null }case inStaticType, which callsDeclaredMethodReturnType(StaticType(receiver), callee).DeclaredMethodReturnTyperesolves a type only when all of these hold:ClassDeclarationinGenerationRoothas that name;ExpectedTypestill takes precedence.Tests
Added to
Coder.Test/Languages/CallResultIntegerDivisionTests.cs:Python_MethodCallResultOnATypedReceiver_MatchesTheCFamilyandJavaScript_MethodCallResultOnATypedReceiver_MatchesTheCFamilyrun the generated code. They check/and%, both into a typed local and in a return, for arguments -7, 7, -9, 9 and 0.UntypedReceiverUnknownClassOrOverloadedMethod_StaysTrueDivisionchecks that an overloaded method, an undeclared class and an untyped receiver all leave the division alone.I checked the two run tests against the code without the fix and both fail as the issue describes (
half_local(-7) = -3.5, expected -3). With the fix they pass. The full suite passes locally: 1324 succeeded, 0 failed, 0 skipped, with Python, Node, Go, Rust and gcc on the path.Generated by Claude Code